﻿using System;

namespace PhiStore.Util
{
    /// <summary>
    /// Static class containing compare methods
    /// </summary>
    public static class Compare
    {
        /// <summary>
        /// Verifies that 2 arrays are equal
        /// NOTE: if both arrays are 'null', 'true' is returned
        /// </summary>
        /// <typeparam name="T">Any IComparable type</typeparam>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns>Equality</returns>
        public static bool ArrayEquals<T>(T[] a, T[] b) where T : IComparable
        {
            if (a == null && b == null)
                return true;

            if (a == null || b == null || a.Length != b.Length)
                return false;

            for (int i = 0; i < a.Length; i++)
            {
                if (a[i].CompareTo(b[i]) != 0)
                {
                    return false;
                }
            }
            return true;
        }
    }
}
